package org.hhchat.leetcode.array;

public class code191_easy {

    static public class Solution {
        // you need to treat n as an unsigned value
        public int hammingWeight(int n) {
            int count=0;
            //！！！注意防止溢出数据的存在问题，需要保证n!=0而不是n>0，另外需要保证使用>>>无符号数右移
            while(n!=0){
                if((n&1)==1){
                    count++;
                }
                n=n>>>1;
            }
            return count;
        }
    }
    public static void main(String[] args){
        System.out.println(new Solution().hammingWeight(11));
    }
}
